﻿using B.S.Base.Write.API.Application.Command;
using MediatR;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Write.API.Application.CommandHandLer
{
    public class DeleteRoleaccountCommandHandLer : IRequestHandler<DeleteRoleaccountCommand, APIResult<object>>
    {
        private readonly IBaseRepostiy<UserRoleModel> userrole;

        public DeleteRoleaccountCommandHandLer(IBaseRepostiy<UserRoleModel> userrole)
        {
            this.userrole = userrole;
        }
        public async Task<APIResult<object>> Handle(DeleteRoleaccountCommand request, CancellationToken cancellationToken)
        {

            var id = userrole.GetAll().FirstOrDefault(x => x.AccountId == request.AccountId && x.RoleId == request.RoleId);
            var list = userrole.GetAll().FirstOrDefault(x => x.UserRoleId == id.UserRoleId);
           await userrole.Delete(list);
            return new APIResult<object>
            {
                Code = ResultCode.Ok,
                Data = 1,
                Message = "删除成功"
            };
        }
    }
}
